//
//  GKJump.swift
//  MySwiftObject
//
//  Created by wangws1990 on 2019/9/5.
//  Copyright © 2019 wangws1990. All rights reserved.
//

import UIKit

class GKJump: NSObject {
    class func jumpToGuideCtrl(completion:((() -> Void))? = nil){
        let user :GKUserModel = GKUserManager.getModel()
        if (user.rankDatas == nil) {
            GKJump.window().rootViewController = GKSexViewController.vcWithCompletion(completion: completion)
        }else{
            if completion != nil {
                completion!();
            }
        }
        GKJump.jumpToLaunchController();
    }
    class func jumpToDetail(bookId:String){
        let vc : GKDetailViewController = GKDetailViewController.vcWithBookId(bookId: bookId) as! GKDetailViewController;
        vc.hidesBottomBarWhenPushed = true;
        UIViewController.rootTopPresentedController().navigationController?.pushViewController(vc, animated: true);
    }
    class func jumpToMore(homeInfo:GKHomeInfo){
        let vc : GKHomeMoreController = GKHomeMoreController.vcWithBookInfo(info: homeInfo) as! GKHomeMoreController;
        vc.hidesBottomBarWhenPushed = true;
        UIViewController.rootTopPresentedController().navigationController?.pushViewController(vc, animated: true);
    }
    class func jumpToClassifyTail(group:String,name:String){
        let vc:GKClassifyTailController = GKClassifyTailController.vcWithGroupAndName(group: group, name: name) as! GKClassifyTailController;
        vc.hidesBottomBarWhenPushed = true;
        UIViewController.rootTopPresentedController().navigationController?.pushViewController(vc, animated: true);
    }
    class func jumpToBookCase(){
        let root : UIViewController =  UIViewController.rootTopPresentedController();
        let vc:GKBookCaseController = GKBookCaseController.init()
        vc.hidesBottomBarWhenPushed = true;
        
        root.navigationController?.pushViewController(vc, animated: true)
    }
    class func jumpToNovel(bookModel :GKBookModel){
        let vc:GKNovelContentController = GKNovelContentController.vcWitBookId(bookModel: bookModel)
        vc.hidesBottomBarWhenPushed = true;
        let nvc : BaseNavigationController = BaseNavigationController.init(rootViewController: vc);
        nvc.modalPresentationStyle = .fullScreen;
        UIViewController.rootTopPresentedController().present(nvc, animated: false, completion: nil);
    }
    class func jumpToBrowse(){
        let vc:GKBrowseController = GKBrowseController.init();
        vc.hidesBottomBarWhenPushed = true;
        UIViewController.rootTopPresentedController().navigationController?.pushViewController(vc, animated: true);
    }
    class func jumpToSearch(){
        let vc:GKSearchHistoryController  = GKSearchHistoryController.init();
        vc.hidesBottomBarWhenPushed = true;
        UIViewController.rootTopPresentedController().navigationController?.pushViewController(vc, animated: false);
    }
    class func jumpToSearchResult(keyWord :String){
        let vc: GKSearchResultController = GKSearchResultController.vcWithKeyWord(keyWord: keyWord);
        vc.hidesBottomBarWhenPushed = true;
        UIViewController.rootTopPresentedController().navigationController?.pushViewController(vc, animated: true);
    }
    @objc class func window() -> UIWindow{
        let app:UIApplication = UIApplication.sharedExtension()!;
        if (app.delegate?.responds(to: #selector(window)))! {
            return ((app.delegate?.window)!)!;
        }
        return app.keyWindow!;
    }
    class func jumpToLaunchController(){
        let vc :UIViewController = UIViewController.rootTopPresentedController();
        let start : GKLaunchController = GKLaunchController();
        let nvc = BaseNavigationController.init(rootViewController: start);
        nvc.modalPresentationStyle = .fullScreen;
        vc.present(nvc, animated: false, completion: nil);
        
    }
}
